package com.uyaer.duobao163;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.uyaer.duobao163.vo.AwardBagManager;
import com.uyaer.duobao163.vo.AwardBagManager.AwardItem;
import com.uyaer.duobao163.vo.AwardItemDescManager;
import com.uyaer.duobaoassist.R;

public class MyBagActivity extends Activity {

	private ArrayList<AwardItem> data;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_bag);

		data = AwardBagManager.getInstance().list;
		
		ListView listView = (ListView) findViewById(R.id.mybag_list);
		
		MyAdapter adapter = new MyAdapter(this);
		listView.setAdapter(adapter);
	}

	@Override
	protected void onStop() {
		super.onStop();
		finish();
	}

	private class MyAdapter extends BaseAdapter {

		private TextView descTF;

		private LayoutInflater mInflater;

		public MyAdapter(Context context) {
			this.mInflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			return data.size();
		}

		@Override
		public Object getItem(int arg0) {
			return data.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			convertView = mInflater.inflate(R.layout.list_item_mybag, null);
			descTF = (TextView) convertView
					.findViewById(R.id.bagitem_lab);
			
				AwardItem vo = data.get(position);
				AwardItemDescManager.ItemDesc info = vo.info;
				String desc = "<font color='#1b8bbf' size ='150%'>"+info.name + "</font><font color='#0b9d07'>(" + vo.num + "/" + info.overlap + ")</font><br/>"
						+ info.desc;
			descTF.setText(Html.fromHtml(desc));
			
			return convertView;
		}
	}
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
}
